﻿using System;
using System.Collections.Generic;
using System.Text;

namespace BITUI.Audio
{
    class AudioData_Ogg : IAudioData
    {
        public string[] ExtNames => new string[] { ".ogg" };

        public bool Load(string filename)
        {
            reader = new NVorbis.VorbisReader(filename);
            return true;
        }
        /// <summary>
        /// 从一个数据流中加载，这个流就交给Music了，不可关闭，Music的Close会一起Close这个流
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public bool Load(System.IO.Stream stream)
        {
            reader = new NVorbis.VorbisReader(stream, true);
            return true;
        }
        public void Dispose()
        {
            this.reader.Dispose();
        }
        public int Freq
        {
            get
            {
                return reader.SampleRate;
            }

        }
        public float Time
        {
            get
            {
                return (float)reader.TotalTime.TotalSeconds;
            }
        }
        public int Channel
        {
            get
            {
                return reader.Channels;
            }
        }
        public float PlayTime
        {
            get
            {
                return (float)reader.DecodedTime.TotalSeconds;
            }
            set
            {
                reader.DecodedTime = TimeSpan.FromSeconds(value);
            }
        }

        public int ReadFloat(float[] data, int offset, int count)
        {
            return reader.ReadSamples(data, offset, count);
        }
        NVorbis.VorbisReader reader = null;
    }

}
